home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.3d26 source / tn3270 / apistg.c < prev    next >
Text File  |  1991-05-27  |  5KB  |  268 lines

  1. /*
  2.  *  tn3270 for the Macintosh Source Code
  3.  *  Brown University Computing and Information Services
  4.  *  Version 2.3d21, January 17, 1991
  5.  *  Copyright (c) 1988, 1989, 1990, 1991 by Brown University and by
  6.  *  Peter John DiCamillo.
  7.  *
  8.  *  Permission is granted to any individual or institution to use, copy,
  9.  *  or redistribute the binary version of this software and its
  10.  *  documentation provided this notice and the copyright notices are
  11.  *  retained.  Permission is granted to any individual or non-profit
  12.  *  institution to use, copy, modify, or redistribute the source files
  13.  *  of this software provided this notice and the copyright notices are
  14.  *  retained.  This software may not be distributed for profit, either
  15.  *  in original form or in derivative works, nor can the source be
  16.  *  distributed to other than an individual or a non-profit institution.
  17.  *  Any  individual or group interested in seeing and/or using these
  18.  *  source files but who are prevented from doing so by the above
  19.  *  constraints should contact Don Wolfe, Assistant Vice-President for
  20.  *  Computer Systems at Brown University, (401) 863-7250, for possible
  21.  *  software licensing of the source developed at Brown.
  22.  *
  23.  *  Brown University and Peter John DiCamillo make no representations
  24.  *  about the suitability of this software for any purpose.
  25.  *
  26.  *  BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
  27.  *  EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  28.  *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  29.  *  WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  */
  32.  
  33. #define __SEG__ api
  34. #include "maclib.h"
  35. #include "termdef.h"
  36. #include "globals.h"
  37.  
  38. #define PARAMNEEDED        5
  39. #define CLIENTNEEDED    2
  40. #define DATANEEDED        5        
  41.  
  42. Ptr myNewPtr();
  43.  
  44. OSErr extendqueue();
  45. PPCParamBlockPtr newparamblock();
  46. clientinfo * newclientrec();
  47. datainfo * newdatablock();
  48. qctl * getnew();
  49.  
  50. initparamblocks()
  51. {
  52. memset(¶mqueue, 0, sizeof(queueinfo));
  53. strcpy(paramqueue.name, "Param");
  54. paramqueue.elemsize = sizeof(paramrec);
  55. paramqueue.minavail = PARAMNEEDED;
  56. }
  57.  
  58. initclientrecs()
  59. {
  60. memset(&clientqueue, 0, sizeof(queueinfo));
  61. strcpy(clientqueue.name, "Client");
  62. clientqueue.elemsize = sizeof(clientrec);
  63. clientqueue.minavail = CLIENTNEEDED;
  64. }
  65.  
  66. initdatablocks()
  67. {
  68. memset(&dataqueue, 0, sizeof(queueinfo));
  69. strcpy(dataqueue.name, "Data");
  70. dataqueue.elemsize = sizeof(datarec);
  71. dataqueue.minavail = DATANEEDED;
  72. }
  73.  
  74. endparamblocks()
  75. {
  76. endqueue(¶mqueue);
  77. }
  78.  
  79. endclientrecs()
  80. {
  81. endqueue(&clientqueue);
  82. }
  83.  
  84. enddatablocks()
  85. {
  86. endqueue(&dataqueue);
  87. }
  88.  
  89. endqueue(qp)
  90. queueinfo *qp;
  91. {
  92. qctl *current, *next;
  93.  
  94. next = qp->first;
  95. while (next != 0) {
  96.     current = next;
  97.     next = (qctl *)current->next;
  98.     DisposPtr((Ptr)current);
  99.     }
  100. qp->first = 0;
  101. qp->stgerr = 0;
  102. qp->spare = 0;
  103. }
  104.  
  105. addparamblocks()
  106. {
  107. addqueue(¶mqueue);
  108. }
  109.  
  110. addclientrecs()
  111. {
  112. addqueue(&clientqueue);
  113. }
  114.  
  115. adddatablocks()
  116. {
  117. addqueue(&dataqueue);
  118. }
  119.  
  120. addqueue(qp)
  121. queueinfo *qp;
  122. {
  123. qctl *current;
  124. short avail, i, needed;
  125. OSErr rc;
  126. /* char msg[120];  ****** */
  127.  
  128. if (qp->stgerr) return;
  129.  
  130. avail = 0;
  131. current = qp->first;
  132. while (current != 0) {
  133.     if (current->inuse == 0) {
  134.         avail++;        
  135.         }
  136.     current = (qctl *)current->next;
  137.     }
  138.  
  139. /*  queue debugging code  ********
  140. if (avail != qp->spare) {
  141.     sprintf(msg, "Queue %s: avail was %d, now %d", qp->name, qp->spare, avail);
  142.     cs.dblevel = 1;
  143.     dbdlg(msg);
  144.     cs.dblevel = 0;
  145.     qp->spare = avail;
  146.     }                     ******** */
  147.  
  148. needed = qp->minavail - avail;
  149. if (needed <= 0) return;
  150. for (i = 0; i < needed; i++) {
  151.     rc = extendqueue(qp);
  152.     if (rc != noErr) break;
  153.     }
  154. if (rc != noErr) qp->stgerr = 1;
  155. }
  156.  
  157. OSErr extendqueue(qp)
  158. queueinfo *qp;
  159. {
  160. qctl *new, *current;
  161.  
  162. new = (qctl *)myNewPtr(qp->elemsize);
  163. if (new == 0) {
  164.     return(mFulErr);
  165.     }
  166. memset(new, 0, qp->elemsize);
  167. if (qp->first == 0) {
  168.     qp->first = new;
  169.     return(noErr);
  170.     }
  171. current = qp->first;
  172. while (current->next != 0) {
  173.     current = (qctl *)current->next;
  174.     }
  175. current->next = new;
  176. return(noErr);
  177. }
  178.  
  179. PPCParamBlockPtr newparamblock()
  180. {
  181. paramrec * prp;
  182.  
  183. prp = (paramrec *)getnew(¶mqueue);
  184. if (prp == 0) return(0);
  185. else return(&(prp->pb));
  186. }
  187.  
  188. clientinfo * newclientrec()
  189. {
  190. clientrec * crp;
  191.  
  192. crp = (clientrec *)getnew(&clientqueue);
  193. if (crp == 0) return(0);
  194. else return(&(crp->client));
  195. }
  196.  
  197. datainfo * newdatablock()
  198. {
  199. datarec * drp;
  200.  
  201. drp = (datarec *)getnew(&dataqueue);
  202. if (drp == 0) return(0);
  203. else return(&(drp->data));
  204. }
  205.  
  206. qctl * getnew(qp)
  207. queueinfo *qp;
  208. {
  209. qctl *current;
  210.         /* Note: this code is designed so that if it is interrupted
  211.            by a copy of itself running at interrupt level, it will
  212.            not allocated the same element twice. */
  213. current = qp->first;
  214. while (current != 0) {
  215.     if (current->inuse == 0) {
  216.         if (current->pend_inuse == 0) {
  217.             current->pend_inuse == 1;
  218.             if (current->inuse == 0) {
  219.                 current->inuse = 1;
  220.                 current->pend_inuse = 0;
  221.                 return(current);
  222.                 }
  223.             else {
  224.                 current->pend_inuse = 0;
  225.                 }
  226.             }
  227.         }
  228.     current = (qctl *)current->next;
  229.     }
  230. return(0);
  231. }
  232.  
  233. disposparamblock(p)
  234. PPCParamBlockPtr p;
  235. {
  236. disposelem((unsigned char *)p, ¶mqueue);
  237. }
  238.  
  239. disposclientrec(p)
  240. clientinfo *p;
  241. {
  242. disposelem((unsigned char *)p, &clientqueue);
  243. }
  244.  
  245. disposdatarec(p)
  246. datainfo *p;
  247. {
  248. disposelem((unsigned char *)p, &dataqueue);
  249. }
  250.  
  251. disposelem(s, qp)
  252. unsigned char *s;
  253. queueinfo *qp;
  254. {
  255. qctl * delete_elem, *current;
  256.  
  257. s -= sizeof(qctl);
  258. delete_elem = (qctl *)s;
  259. current = qp->first;
  260. while (current != 0) {
  261.     if (current == delete_elem) {
  262.         current->inuse = 0;
  263.         return;
  264.         }
  265.     current = (qctl *)current->next;
  266.     }
  267. }
  268.